home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / GXMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  8.9 KB  |  317 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        GXMath.h
  3.  
  4.      Contains:    QuickDraw GX math routine interfaces.
  5.  
  6.      Version:    Technology:    Quickdraw GX 1.1
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1994-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __GXMATH__
  18. #define __GXMATH__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21.     #include <ConditionalMacros.h>
  22. #endif
  23.  
  24. #ifndef __MACTYPES__
  25.     #include <MacTypes.h>
  26. #endif
  27.  
  28. #ifndef __FIXMATH__
  29.     #include <FixMath.h>
  30. #endif
  31.  
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. #if defined(__MWERKS__) && TARGET_CPU_68K
  56.     #pragma push
  57.     #pragma pointers_in_D0
  58. #endif
  59.  
  60.  
  61.  
  62. struct gxPoint {
  63.     Fixed                             x;
  64.     Fixed                             y;
  65. };
  66. typedef struct gxPoint                    gxPoint;
  67.  
  68. typedef unsigned short                     gxColorValue;
  69.  
  70. struct gxPolar {
  71.     Fixed                             radius;
  72.     Fixed                             angle;
  73. };
  74. typedef struct gxPolar                    gxPolar;
  75.  
  76. struct gxMapping {
  77.     Fixed                             map[3][3];
  78. };
  79. typedef struct gxMapping                gxMapping;
  80. #define    gxColorValue1            ((gxColorValue) 0x0000FFFF)
  81. #define  gxPositiveInfinity        ((long) 0x7FFFFFFFL)
  82. #define    gxNegativeInfinity        ((long) 0x80000000L)
  83.  
  84. EXTERN_API_C( gxMapping *)
  85. CopyToMapping                    (gxMapping *            target,
  86.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0031, 0xA832);
  87.  
  88. EXTERN_API_C( gxMapping *)
  89. InvertMapping                    (gxMapping *            target,
  90.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0032, 0xA832);
  91.  
  92. EXTERN_API_C( gxMapping *)
  93. MapMapping                        (gxMapping *            target,
  94.                                  const gxMapping *        source)                                THREEWORDINLINE(0x303C, 0x0033, 0xA832);
  95.  
  96. EXTERN_API_C( gxMapping *)
  97. MoveMapping                        (gxMapping *            target,
  98.                                  Fixed                     hOffset,
  99.                                  Fixed                     vOffset)                            THREEWORDINLINE(0x303C, 0x0034, 0xA832);
  100.  
  101. EXTERN_API_C( gxMapping *)
  102. MoveMappingTo                    (gxMapping *            target,
  103.                                  Fixed                     hPosition,
  104.                                  Fixed                     vPosition)                            THREEWORDINLINE(0x303C, 0x0035, 0xA832);
  105.  
  106. EXTERN_API_C( gxMapping *)
  107. NormalizeMapping                (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0036, 0xA832);
  108.  
  109. EXTERN_API_C( gxMapping *)
  110. RotateMapping                    (gxMapping *            target,
  111.                                  Fixed                     angle,
  112.                                  Fixed                     xCenter,
  113.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0037, 0xA832);
  114.  
  115. EXTERN_API_C( gxMapping *)
  116. ScaleMapping                    (gxMapping *            target,
  117.                                  Fixed                     hFactor,
  118.                                  Fixed                     vFactor,
  119.                                  Fixed                     xCenter,
  120.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x0038, 0xA832);
  121.  
  122. EXTERN_API_C( gxMapping *)
  123. ResetMapping                    (gxMapping *            target)                                THREEWORDINLINE(0x303C, 0x0039, 0xA832);
  124.  
  125. EXTERN_API_C( gxMapping *)
  126. SkewMapping                        (gxMapping *            target,
  127.                                  Fixed                     skewX,
  128.                                  Fixed                     skewY,
  129.                                  Fixed                     xCenter,
  130.                                  Fixed                     yCenter)                            THREEWORDINLINE(0x303C, 0x003A, 0xA832);
  131.  
  132. EXTERN_API_C( void )
  133. MapPoints                        (const gxMapping *        source,
  134.                                  long                     count,
  135.                                  gxPoint                 theVector[])                            THREEWORDINLINE(0x303C, 0x003B, 0xA832);
  136.  
  137. EXTERN_API_C( short )
  138. FirstBit                        (unsigned long             x)                                    THREEWORDINLINE(0x303C, 0x003C, 0xA832);
  139.  
  140. EXTERN_API_C( short )
  141. WideScale                        (const wide *            source)                                THREEWORDINLINE(0x303C, 0x003D, 0xA832);
  142.  
  143. EXTERN_API_C( short )
  144. LinearRoot                        (Fixed                     first,
  145.                                  Fixed                     last,
  146.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003E, 0xA832);
  147.  
  148. EXTERN_API_C( short )
  149. QuadraticRoot                    (Fixed                     first,
  150.                                  Fixed                     control,
  151.                                  Fixed                     last,
  152.                                  Fract                     t[])                                    THREEWORDINLINE(0x303C, 0x003F, 0xA832);
  153.  
  154. EXTERN_API_C( gxPoint *)
  155. PolarToPoint                    (const gxPolar *        ra,
  156.                                  gxPoint *                xy)                                    THREEWORDINLINE(0x303C, 0x0040, 0xA832);
  157.  
  158. EXTERN_API_C( gxPolar *)
  159. PointToPolar                    (const gxPoint *        xy,
  160.                                  gxPolar *                ra)                                    THREEWORDINLINE(0x303C, 0x0041, 0xA832);
  161.  
  162. EXTERN_API_C( Fract )
  163. FractCubeRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0042, 0xA832);
  164.  
  165. EXTERN_API_C( Fract )
  166. FractDivide                        (Fract                     dividend,
  167.                                  Fract                     divisor)                            THREEWORDINLINE(0x303C, 0x0043, 0xA832);
  168.  
  169. EXTERN_API_C( Fract )
  170. FractMultiply                    (Fract                     multiplicand,
  171.                                  Fract                     multiplier)                            THREEWORDINLINE(0x303C, 0x0044, 0xA832);
  172.  
  173. EXTERN_API_C( Fract )
  174. FractSineCosine                    (Fixed                     degrees,
  175.                                  Fract *                cosine)                                THREEWORDINLINE(0x303C, 0x0045, 0xA832);
  176.  
  177. EXTERN_API_C( Fract )
  178. FractSquareRoot                    (Fract                     source)                                THREEWORDINLINE(0x303C, 0x0046, 0xA832);
  179.  
  180. EXTERN_API_C( Fixed )
  181. FixedDivide                        (Fixed                     dividend,
  182.                                  Fixed                     divisor)                            THREEWORDINLINE(0x303C, 0x0047, 0xA832);
  183.  
  184. EXTERN_API_C( Fixed )
  185. FixedMultiply                    (Fixed                     multiplicand,
  186.                                  Fixed                     multiplier)                            THREEWORDINLINE(0x303C, 0x0048, 0xA832);
  187.  
  188. /* This next call is (source * multiplier / divisor) -- it avoids underflow, overflow by using wides */
  189. EXTERN_API_C( long )
  190. MultiplyDivide                    (long                     source,
  191.                                  long                     multiplier,
  192.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x0049, 0xA832);
  193.  
  194. EXTERN_API_C( unsigned long )
  195. Magnitude                        (long                     deltaX,
  196.                                  long                     deltaY)                                THREEWORDINLINE(0x303C, 0x004A, 0xA832);
  197.  
  198. EXTERN_API_C( long )
  199. VectorMultiplyDivide            (long                     count,
  200.                                  const long *            vector1,
  201.                                  long                     step1,
  202.                                  const long *            vector2,
  203.                                  long                     step2,
  204.                                  long                     divisor)                            THREEWORDINLINE(0x303C, 0x004B, 0xA832);
  205.  
  206.  
  207.  
  208.  
  209. /* wide operations are defined within FixMath.h for PowerPC */
  210. #if TARGET_OS_MAC && TARGET_CPU_68K
  211. EXTERN_API_C( wide *)
  212. WideAdd                            (wide *                    target,
  213.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004C, 0xA832);
  214.  
  215. EXTERN_API_C( short )
  216. WideCompare                        (const wide *            target,
  217.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x004D, 0xA832);
  218.  
  219. EXTERN_API_C( wide *)
  220. WideNegate                        (wide *                    target)                                THREEWORDINLINE(0x303C, 0x004E, 0xA832);
  221.  
  222. EXTERN_API_C( wide *)
  223. WideShift                        (wide *                    target,
  224.                                  long                     shift)                                THREEWORDINLINE(0x303C, 0x004F, 0xA832);
  225.  
  226. EXTERN_API_C( unsigned long )
  227. WideSquareRoot                    (const wide *            source)                                THREEWORDINLINE(0x303C, 0x0050, 0xA832);
  228.  
  229. EXTERN_API_C( wide *)
  230. WideSubtract                    (wide *                    target,
  231.                                  const wide *            source)                                THREEWORDINLINE(0x303C, 0x0051, 0xA832);
  232.  
  233. EXTERN_API_C( wide *)
  234. WideMultiply                    (long                     multiplicand,
  235.                                  long                     multiplier,
  236.                                  wide *                    target)                                THREEWORDINLINE(0x303C, 0x0052, 0xA832);
  237.  
  238. /* returns the quotient */
  239. EXTERN_API_C( long )
  240. WideDivide                        (const wide *            dividend,
  241.                                  long                     divisor,
  242.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0053, 0xA832);
  243.  
  244. /* quotient replaces dividend */
  245. EXTERN_API_C( wide *)
  246. WideWideDivide                    (wide *                    dividend,
  247.                                  long                     divisor,
  248.                                  long *                    remainder)                            THREEWORDINLINE(0x303C, 0x0055, 0xA832);
  249.  
  250. #endif  /* TARGET_OS_MAC && TARGET_CPU_68K */
  251.  
  252.  
  253.  
  254. EXTERN_API_C( wide *)
  255. VectorMultiply                    (long                     count,
  256.                                  const long *            vector1,
  257.                                  long                     step1,
  258.                                  const long *            vector2,
  259.                                  long                     step2,
  260.                                  wide *                    dot)                                THREEWORDINLINE(0x303C, 0x0054, 0xA832);
  261.  
  262. EXTERN_API_C( unsigned long )
  263. RandomBits                        (long                     count,
  264.                                  long                     focus)                                THREEWORDINLINE(0x303C, 0x0056, 0xA832);
  265.  
  266. EXTERN_API_C( void )
  267. SetRandomSeed                    (const wide *            seed)                                THREEWORDINLINE(0x303C, 0x0057, 0xA832);
  268.  
  269. EXTERN_API_C( wide *)
  270. GetRandomSeed                    (wide *                    seed)                                THREEWORDINLINE(0x303C, 0x0058, 0xA832);
  271.  
  272.  
  273. #define FixedRound(a)        ((short)((Fixed)(a) + fixed1/2 >> 16))
  274. #define FixedSquareRoot(a)    ((Fixed)FractSquareRoot(a) + 64 >> 7)
  275. #define FixedTruncate(a)        ((short)((Fixed)(a) >> 16))
  276. #define FixedToFract(a)        ((Fract)(a) << 14)
  277. #define FractToFixed(a)        ((Fixed)(a) + 8192L >> 14)
  278. #define FixedToInt(a)       ((short)((Fixed)(a) + fixed1/2 >> 16))
  279. #define IntToFixed(a)       ((Fixed)(a) << 16)
  280. #define FixedToFloat(a)     ((float)(a) / fixed1)
  281. #define FloatToFixed(a)         ((Fixed)((float)(a) * fixed1))
  282. #define FractToFloat(a)     ((float)(a) / fract1)
  283. #define FloatToFract(a)     ((Fract)((float)(a) * fract1))
  284. #define ColorToFract(a)     (((Fract) (a) << 14) + ((Fract)(a) + 2 >> 2))
  285. #define FractToColor(a)     ((gxColorValue) ((a) - ((a) >> 16) + 8191 >> 14))
  286. #ifndef ff    /* ff is already defined on some platforms */
  287. #define ff(a)               IntToFixed(a)
  288. #define fl(a)               FloatToFixed(a)
  289. #endif
  290.  
  291.  
  292. #if defined(__MWERKS__) && TARGET_CPU_68K
  293.     #pragma pop
  294. #endif
  295.  
  296.  
  297. #if PRAGMA_STRUCT_ALIGN
  298.     #pragma options align=reset
  299. #elif PRAGMA_STRUCT_PACKPUSH
  300.     #pragma pack(pop)
  301. #elif PRAGMA_STRUCT_PACK
  302.     #pragma pack()
  303. #endif
  304.  
  305. #ifdef PRAGMA_IMPORT_OFF
  306. #pragma import off
  307. #elif PRAGMA_IMPORT
  308. #pragma import reset
  309. #endif
  310.  
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314.  
  315. #endif /* __GXMATH__ */
  316.  
  317.